<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
#div1{
  width: 300px;
  height: 300px;
  background: red;
  transition: all 0.5s ease;
}

</style>

<body>

  <div id="div1" onmouseover="changeColor('green')" onmouseout="changeColor('red')">

  </div>
  <script>
    function changeColor(color) {
      let div1 = document.getElementById("div1")
      div1.style.width = "300px"
      div1.style.height = "300px"
      div1.style.background = color
    }
  </script>

</body>

</html>